package com.wisedu.wec.bank.biz;

import com.wisedu.wec.bank.api.dto.PayStatus;
import com.wisedu.wec.bank.common.exception.DaoException;
import com.wisedu.wec.bank.dal.sqlDao.BankDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: wec-mall-bank-apps
 * @description:
 * @author: Liuzidan
 * @create: 2021-01-08 11:08
 **/

@Service
public class BankServiceImpl implements IBankService {
    @Autowired
    BankDao bankDao;

    @Override
    public PayStatus productPay(String accountId, Double price) {

        try {
            if (bankDao.balanceDecr(accountId, price) > 0) {
                return PayStatus.PAY_SUCCESS;
            }
            return PayStatus.PAY_FAIL;
        } catch (DaoException e) {
            return PayStatus.PAY_FAIL;
        }


    }

    @Override
    public PayStatus refund(String accountId, Double price) {
        try {
            if (bankDao.balanceIncr(accountId, price) > 0) {
                return PayStatus.REFUND_SUCCESS;
            }
            return PayStatus.REFUND_FAIL;
        } catch (DaoException e) {
            return PayStatus.REFUND_FAIL;
        }
    }
}
